package com.zzyl.serve.controller;

import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.serve.domain.NursingTask;
import com.zzyl.serve.dto.NursingTaskPageDto;
import com.zzyl.serve.service.INursingTaskService;
import com.zzyl.serve.vo.NursingTaskUpdateVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 护理任务Controller
 *
 * @author liuyp
 * @date 2025-07-30
 */
@RestController
@RequestMapping("/nursing/task")
@Api(tags = "护理任务管理")
public class NursingTaskController extends BaseController {
    @Autowired
    private INursingTaskService nursingTaskService;

    @PutMapping("/cancel")
    @ApiOperation("取消任务")
    public AjaxResult cancelTask(@RequestBody NursingTaskUpdateVo nursingTaskUpdateVo) {
        this.nursingTaskService.cancelTask(nursingTaskUpdateVo);
        return this.success();
    }

    @PutMapping("/updateTime")
    @ApiOperation("任务改期")
    public AjaxResult updateTime(@RequestBody NursingTaskUpdateVo nursingTaskUpdateVo) {
        this.nursingTaskService.updateTime(nursingTaskUpdateVo);
        return this.success();
    }

    @PutMapping("/do")
    @ApiOperation("执行任务")
    public AjaxResult doTask(@RequestBody NursingTaskUpdateVo nursingTaskUpdateVo) {
        this.nursingTaskService.doTask(nursingTaskUpdateVo);
        return this.success();
    }

    /**
     * 查询护理任务列表
     */
    @GetMapping("/list")
    @ApiOperation(value = "获取护理任务列表")
    public TableDataInfo<NursingTask> list(@ApiParam(value = "护理任务查询条件") NursingTaskPageDto nursingTaskPageDto) {

        return this.nursingTaskService.selectNursingTaskList(nursingTaskPageDto);
    }


    /**
     * 获取护理任务详细信息
     */
    @GetMapping(value = "/{id}")
    @ApiOperation("获取护理任务详细信息")
    public R<NursingTask> getInfo(@ApiParam(value = "护理任务ID", required = true) @PathVariable("id") Long id) {
        return R.ok(this.nursingTaskService.selectNursingTaskByIds(id));
    }

    /**
     * 新增护理任务
     */
    @Log(title = "护理任务", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增护理任务")
    public AjaxResult add(@ApiParam(value = "护理任务实体", required = true) @RequestBody NursingTask nursingTask) {
        return this.toAjax(this.nursingTaskService.insertNursingTask(nursingTask));
    }

    /**
     * 修改护理任务
     */
    @Log(title = "护理任务", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改护理任务")
    public AjaxResult edit(@ApiParam(value = "护理任务实体", required = true) @RequestBody NursingTask nursingTask) {
        return this.toAjax(this.nursingTaskService.updateNursingTask(nursingTask));
    }

    /**
     * 删除护理任务
     */
    @Log(title = "护理任务", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation("删除护理任务")
    public AjaxResult remove(@ApiParam(value = "护理任务ID数组", required = true) @PathVariable Long[] ids) {
        return this.toAjax(this.nursingTaskService.deleteNursingTaskByIds(ids));
    }
}
